package com.cloudkinto.enumType.workOrder;

import com.baomidou.mybatisplus.core.enums.IEnum;
import com.cloudkinto.vo.common.CommonKvVo;

import java.util.ArrayList;
import java.util.List;

/**
 * 工单状态
 *
 * @author long
 */
public enum WorkOrderStatusEnum implements IEnum<Integer> {

    /**
     *
     */
    zero(0, "待审核"),
    one(1, "已审核"),
    two(2, "处理完成"),
    three(3, "已作废");

    private final int code;
    private final String desc;

    WorkOrderStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public Integer getValue() {
        return code;
    }

    public static List<CommonKvVo> getWorkOrderStatusList() {
        ArrayList<CommonKvVo> list = new ArrayList<>();
        for (WorkOrderStatusEnum claimStatusEnum : values()) {
            list.add(
                    CommonKvVo.builder()
                            .label(claimStatusEnum.desc)
                            .value(claimStatusEnum.getValue())
                            .build()
            );
        }
        return list;
    }

    public static String getDescByCode(Integer code) {
        for (WorkOrderStatusEnum claimStatusEnum : values()) {
            if (claimStatusEnum.getValue().equals(code)) {
                return claimStatusEnum.desc;
            }
        }
        return null;
    }

    public static Integer getCodeByDesc(String desc) {
        for (WorkOrderStatusEnum claimStatusEnum : values()) {
            if (claimStatusEnum.desc.equals(desc)) {
                return claimStatusEnum.getValue();
            }
        }
        return null;
    }
}
